<template>
    <div class="viewExplorer-event">
        <div v-if="animationList.length">
            <div class="view-contenier" :class="{ 'view-active': item.id == active }" v-for="(item, index) in animationList"
                :key="index" @click="itemSelect(item)">{{ item.name }}</div>
        </div>
        <div v-else class="page-title">
            暂无，导览列表
        </div>
    </div>
</template>

<script>
import bus from '@/js/event/bus.js';
import util from '@/js/util/util.js';
export default {
    name: 'ViewExplorer',
    props: {
        eventData: {
            type: Array,
            default: []
        }
    },
    data() {
        return {
            animationList: [],
            active: 0
        };
    },
    mounted() {
        bus.on('getEventData', this.getEventData);
        this.$nextTick(async () => {
            if (this.eventData.length > 0 && this.eventData[0].event === 'viewExplorer') {
                await this.get();
                this.setEventData(this.eventData[0]);
            } else {
                await this.get();
            }
        });
    },
    destroyed() {
        bus.off('getEventData', this.getEventData);
    },
    methods: {
        getEventData() {
            if (util.isBlank(this.active)) {
                return {
                    error: true,
                    message: ['请选择导览！']
                };
            } else {
                return {
                    id: this.active,
                    name: this.animationList[this.active].name
                };
            }
        },
        setEventData(event) {
            this.active = event.param.id;
        },
        async get() {
            let result = await this.$store.dispatch('getAnimationList');
            this.animationList = result.data;
        },
        itemSelect(item) {
            this.active = item.id;
        }
    },
}
</script>

<style lang="scss" scoped>
.viewExplorer-event {
    height: 100%;
    position: relative;
}

.view-contenier {
    font-weight: 600;
    line-height: 30px;
    font-size: 12px;
    color: #ffffffe6;
    padding-left: 10px;
    border-radius: 4px;
    margin-bottom: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;

    &:hover {
        background: #ffffff33;
    }
}

.view-active {
    background: #ffffff33;
}
.page-title {
    display: flex;
    height: 65px;
    justify-content: center;
    align-items: center;
    color: #ffffffff;
    font-size: 12px;
}
</style>